package com.mashibing.juc.c_026_00_interview.A1B2C3;

import java.util.concurrent.Semaphore;

public class T14_Semaphore_not_work {
  public static void main(String[] args) {
    //
    char[] aI = "1234567".toCharArray();
    char[] aC = "ABCDEFG".toCharArray();
    Semaphore semaphore1 = new Semaphore(1);
    Semaphore semaphore2 = new Semaphore(1);

    new Thread(
            () -> {
              for (char c : aI) {
                //
                try {
                  semaphore2.acquire();
                  System.out.println(c);
                  semaphore1.release();
                } catch (InterruptedException e) {

                }
              }
            })
        .start();

    new Thread(
            () -> {
              for (char c : aC) {
                try {
                  semaphore1.acquire();
                  System.out.println(c);
                  semaphore2.release();
                } catch (InterruptedException e) {

                }
              }
            })
        .start();
  }
}
